<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" />
    <title>amis demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <link rel="stylesheet" href="sdk.css" />
    <link rel="stylesheet" href="helper.css" />
    <link rel="stylesheet" href="iconfont.css" />
    <!-- 这是默认主题所需的，如果是其他主题则不需要 -->
    <!-- 从 1.1.0 开始 sdk.css 将不支持 IE 11，如果要支持 IE11 请引用这个 css，并把前面那个删了 -->
    <!-- <link rel="stylesheet" href="sdk-ie11.css" /> -->
    <!-- 不过 amis 开发团队几乎没测试过 IE 11 下的效果，所以可能有细节功能用不了，如果发现请报 issue -->
    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script src="sdk.js"></script>
<script type="text/javascript">

        let amis = amisRequire('amis/embed');
        // 通过替换下面这个配置来生成不同页面
        let amisJSON = {
            type: 'page',
            title: '表单页面',
            body: {
                name:"form1",
                type: 'form',
                mode: 'horizontal',
                "data":{
                    "checkKey":"${_|now|date:x}"
                },
                api: {
                    "method": "post",
                    "url": "http://localhost:8080/jeecg-boot/sys/login",
                    "convertKeyToPath": false,
                    "data": {
                        "username":"${name}",
                        "password":"${password}",
                        "captcha":"${yzm-input}",
                        "checkKey":"${checkKey}",
                        "remember_me":true
                    },
                    adaptor: function (payload, response) {
                        if( response.data.status == '0'){
                            localStorage.setItem('token', response.data.data.token);
                            localStorage.setItem('userInfo', JSON.stringify(response.data.data.userInfo));
                            this.window.location.href = "list.html";
                        }
                        return payload;
                    }
                },
                body: [
                    {
                        label: 'Name',
                        type: 'input-text',
                        name: 'name'
                    },
                    {
                        label: '密码',
                        type: 'input-password',
                        name: 'password'
                    },
                    {
                        label: '验证码',
                        name:'yzm-input',
                        type: 'input-text',
                    },
                    {
                        "type": "service",
                        "name":"yzm",
                        "api": {
                            "method": "get",
                            "url": "http://localhost:8080/jeecg-boot/sys/randomImage/${checkKey}?_t=${checkKey}",
                            "cache": 1
                        },
                        "body": {
                            "label": " ",
                            "type": "static-image",
                            "width":"4rem",
                            "height":"1.5rem",
                            "thumbMode":"w-full",
                            "src": "${result}",
                            "clickAction": {
                                "actionType": "reload",
                                "target": "form1.yzm"
                            }
                        }
                    }
                ]
            }
        };
        let amisScoped = amis.embed('#root', amisJSON,{
            'data':{'test':'111'}
        },{
            requestAdaptor:function(api){
                return {
                    ...api,
                    headers:{
                        'X-Access-Token':localStorage.getItem("token"),
                    }
                };
            },
            responseAdaptor:function(api, response, query, request){
                response.status = response.code;
                if( response.status == '200'){
                    response.status = '0';
                }
                response.data = response.result;
                response.result = null;
                response.msg = response.message;
                return response;
            },
        });

</script>
</body>
</html>
